/**
 * 监控列表
*/

var wwj_monitor = new Object({
    table:null,
    init:function(){
        if(null != this.table)
            return;
        this.queryInfo();
    },
    queryInfo:function(){
        this.table = $('#tb_wwj_mg').bootstrapTable({
            url: contextPath + '/wwj/monitor/listData.json',
            responseHandler: function (res) {
                return res.data;
            },
            queryParams: function (params) {
                return params;
            },
            pagination: true,
            pageList: '[10,20, 50, 100]',
            //showColumns: true,
            showRefresh: true,
            showToggle: true,
            //showPaginationSwitch:true,
            sidePagination: 'server',
            //striped:true,
            sortable: false,
            height: 700,
            search: true,
            searchAlign: 'left',
          /*  toolbar: '<div style="float: left;margin-right:5px;">' +
            '    <button class="btn btn-default" type="button" onclick="agent_mg.add()">' +
            '        <i style="margin-right:2px;" class="fa fa-search"></i>' +
            '        <span>新增</span>' +
            '    </button>' +
            '</div>',*/
            idField: 'id',
            uniqueId: 'id',
            //singleSelect: true,
            clickToSelect: true,
            columns: [{
                field: 'createTime',
                title: '注册时间',
                align: 'center',
                width: 100,
                formatter:function(value,row,index){
                    return (new Date(value)).Format("yyyy-MM-dd hh:mm")
                }
            },{
                field: 'code',
                title: '设备编号',
                align: 'center',
                width: 100
            }, {
                field: 'ip',
                title: '设备IP',
                width: 100
            }, {
                field: 'roomId',
                title: '直播间id',
                width: 100
            }, {
                field: 'status',
                title: '使用状态',
                width: 60,
                formatter:function(value,row,index){
                    if(value == 1){
                        return '空闲'
                    }else if(value == 2){
                        return '使用中'
                    }else if(value == 3){
                        return '维护'
                    } else if(value == 0) {
                        return '初始化'
                    }
                }
            }, {
                field: 'probability',
                title: '概率',
                width: 60
            }, {
                field: 'isOnline',
                title: '在线状态',
                width: 60,
                formatter:function(value,row,index){
                    if(value == 0){
                        return '<font color="red">离线</font>'
                    }else{
                        return '<font color="green">在线</font>'
                    }
                }
            },{
                field: 'updateTime',
                title: '更新时间',
                align: 'center',
                width: 100,
                formatter:function(value,row,index){
                    return (new Date(value)).Format("yyyy-MM-dd hh:mm")
                }
            },{
                field: 'op',
                title: '操作',
                align: 'center',
                width: 100,
                formatter: function (value, row, index) {
                    var strHtml = '';
                        //strHtml += '<a href="javascript:void(0);" onclick="client_list.edit('+row.id+',\''+row.name+'\','+row.ratio+')">编辑</a>&nbsp;&nbsp;';
                    strHtml = '<div class="btn-group">' +
                    '<button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown">更多<i class="fa fa-caret-down"></i></button>' +
                    '   <ul class="dropdown-menu">'+
                    '       <li><a href="javascript:void(0);" onclick="wwj_monitor.edit('+row.id+','+row.status+',\''+row.code+'\')">编辑</a></li>'+
                    '   </ul>'+
                    '</div>'
                    return strHtml;
                }
            }]
        });
        $('.search input').attr("placeholder", "搜索设备编号");
    },
    edit:function(id,status,code){
        var editMachineModal = '<div id="editMachineModal" class="modal fade" tabindex="-1" role="dialog" style="display: none;">'+
            '   <div class="modal-dialog">'+
            '       <div class="modal-content">'+
            '           <div class="modal-header">'+
            '               <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>'+
            '               <h4 class="modal-title">设备ID：'+code+'正在编辑</h4>'+
            '           </div>'+
            '           <div class="modal-body">' +
            '               <form class="form-horizontal" id="editMachineForm">'+
            '                          <input type="hidden" name="id" value="'+id+'">'+
            '                   <div class="form-group">'+
            '                       <label class="col-sm-3 control-label">使用状态：</label>'+
            '                       <div class="col-sm-9">';
            if(status == 1) {
                editMachineModal += '    ' +
                    '<div class="radio" style="margin-top: 0;float:left;margin-right:50px">' +
                    '                       <lable>' +
                    '                           <input type="radio" name="status" value="0" />' +
                    '                           <span class="lbl">初始化</span>' +
                    '                           </lable>' +
                    '                   </div>&nbsp;&nbsp;&nbsp;'+
                    '<div class="radio" style="margin-top: 0;float:left;margin-right:50px">' +
                    '                       <lable>' +
                    '                           <input type="radio" name="status" value="1" checked="true"/>' +
                    '                           <span class="lbl">空闲</span>' +
                '                           </lable>' +
                    '                   </div>&nbsp;&nbsp;&nbsp;'+
                        '               <div class="radio" style="margin-top: 0;float:left;margin-right:50px">' +
                    '                       <lable>' +
                    '                               <input type="radio" name="status" value="2" />' +
                    '                               <span class="lbl">使用中</span>' +
                    '                       </lable>' +
                    '                   </div>&nbsp;&nbsp;&nbsp;'+
                        '                <div class="radio" style="margin-top: 0;float:left;">' +
                    '                       <lable ><input type="radio"  name="status" value="3" /><span class="lbl">维护</span></lable>' +
                    '                   </div>' +
                    '';
            }else if(status == 2){
                editMachineModal += '    <div class="radio" style="margin-top: 0;float:left;margin-right:50px"><lable ><input type="radio" name="status" value="0" /><span class="lbl">初始化</span></lable></div>&nbsp;&nbsp;&nbsp;'+
                    '               <div class="radio" style="margin-top: 0;float:left;margin-right:50px"><lable ><input type="radio"  name="status" value="1" /><span class="lbl">空闲</span></lable></div>&nbsp;&nbsp;&nbsp;'+
                    '               <div class="radio" style="margin-top: 0;float:left;margin-right:50px"><lable ><input type="radio"  name="status" value="2" checked="true" /><span class="lbl">使用中</span></lable></div>&nbsp;&nbsp;&nbsp;'+
                    '                <div class="radio" style="margin-top: 0;float:left;margin-right:50px"><lable><input type="radio"  name="status" value="3" /><span class="lbl">维护</span></lable></div>';
            }else if(status == 3){
                editMachineModal += '    <div class="radio" style="margin-top: 0;float:left;margin-right:50px"><lable ><input type="radio"  name="status" value="0" /><span class="lbl">初始化</span></lable></div>&nbsp;&nbsp;&nbsp;'+
                    '               <div class="radio" style="margin-top: 0;float:left;margin-right:50px"><lable ><input type="radio"   name="status" value="1"  /><span class="lbl">空闲</span></lable></div>&nbsp;&nbsp;&nbsp;'+
                    '               <div class="radio" style="margin-top: 0;float:left;margin-right:50px"><lable ><input type="radio"   name="status" value="2"  /><span class="lbl">使用中</span></lable></div>&nbsp;&nbsp;&nbsp;'+
                    '                <div class="radio" style="margin-top: 0;float:left;margin-right:50px"><lable ><input type="radio"  name="status" value="3" checked="true" /><span class="lbl">维护</span></lable></div>&nbsp;&nbsp;&nbsp;';
            } else if(status == 0) {
                editMachineModal += '    <div class="radio" style="margin-top: 0;float:left;margin-right:50px"><lable ><input type="radio"  name="status" value="0" checked="true"/><span class="lbl">初始化</span></lable></div>&nbsp;&nbsp;&nbsp;'+
                    '               <div class="radio" style="margin-top: 0;float:left;margin-right:50px"><lable ><input type="radio"   name="status" value="1"  /><span class="lbl">空闲</span></lable></div>&nbsp;&nbsp;&nbsp;'+
                    '               <div class="radio" style="margin-top: 0;float:left;margin-right:50px"><lable ><input type="radio"   name="status" value="2"  /><span class="lbl">使用中</span></lable></div>&nbsp;&nbsp;&nbsp;'+
                    '                <div class="radio" style="margin-top: 0;float:left;margin-right:50px"><lable ><input type="radio"  name="status" value="3" /><span class="lbl">维护</span></lable></div>&nbsp;&nbsp;&nbsp;';
            }
            editMachineModal +='</div>'+
            '                   </div>'+
            '               </form>'+
            '           </div>' +
            '           <div class="modal-footer" style="text-align:center">'+
            '               <button type="button" class="btn btn-primary"  onclick="wwj_monitor.editSubmit()" >保存</button>'+
            '               <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>'+
            '           </div>'+
            '       </div>'+
            '   </div>'+
            '</div>';

        /**
         * 添加html中，隐藏
         */
        document.body.appendChild($(editMachineModal)[0]);
        $('#editMachineModal').on('hidden.bs.modal', function () {
            document.body.removeChild($('#editMachineModal')[0]);
        });
        //wwj_mg.queryInfo();
        //显示
        $("#editMachineModal").modal('show')
    },
    editSubmit:function(){
        $.ajax({
            url:contextPath+'/wwj/monitor/change',
            data:$('#editMachineForm').serialize(),
            success:function(res){

                alert_message('保存成功');
            },
            error:function(){
                alert_message('保存错误，请联系管理员');
            }
        });
        wwj_monitor.table.bootstrapTable('refresh');
        //隐藏
        $("#editMachineModal").modal('hide')
    }
});